package com.lcj.login;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import java.util.ArrayList;
import java.util.List;

public class rencai {
    /*以下是模拟登陆程序*/
    /*输入你的用户名及密码 ，这里输入*/
    private static String userName = "15874991816";
    private static String password = "cx821202";
 //   private static String redirectURL = "http://www.renren.com/465530468/profile?v=info_timeline";
    // Don't change the following URL       http://zp.hnzpsc.com/index.php?m=Home&c=Members&a=login
    private static String renRenLoginURL = "http://zp.hnzpsc.com/index.php?m=Home&c=Members&a=login";
    // The HttpClient is used in one session
    private HttpResponse response;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    /*输入抓包的参数，即传递的参数*/
    private boolean login() throws Exception {
        HttpPost httpost = new HttpPost(renRenLoginURL);
        // All the parameters post to the web site
        //建立一个NameValuePair数组，用于存储欲传送的参数，添加相关参数，见上图中的参数
        //"username": $("#username").val(),"password": $("#password").val(),"expire":expire,"url":window.location.href,"postcaptcha":$("#postcaptcha").val(),"time": new Date().getTime(),"act":"do_login"
      //  httpost.addHeader("Cookie","think_template=default; PHPSESSID=411dvvuq4roe9sr5v9cekcku62; ip_info_222_247_41_35=think%3A%7B%22ip%22%3A%22222.247.41.35%22%2C%22province%22%3A%22%25E6%25B9%2596%25E5%258D%2597%22%2C%22city%22%3A%22%25E9%2595%25BF%25E6%25B2%2599%22%2C%22district%22%3A%22XX%22%7D; _subsite_domain=http%3A%2F%2Fzp.hnzpsc.com; Hm_lvt_f55ba935b4c78a4baa86b78a2ea326fa=1537175247,1537407062; think_language=zh-CN; Hm_lpvt_f55ba935b4c78a4baa86b78a2ea326fa=1537412850");
        httpost.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");
        httpost.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
        httpost.addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        httpost.addHeader("X-Requested-With","XMLHttpRequest");
       // httpost.addHeader("Origin","http://zp.hnzpsc.com");
      //  httpost.addHeader("Referer","http://zp.hnzpsc.com/members/login.html");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();

        nvps.add(new BasicNameValuePair("username", userName));
        nvps.add(new BasicNameValuePair("password", password));
        nvps.add(new BasicNameValuePair("expire", "1"));

        nvps.add(new BasicNameValuePair("geetest_challenge", ""));

        nvps.add(new BasicNameValuePair("geetest_validate", ""));
        nvps.add(new BasicNameValuePair("geetest_seccode",""));




        /*登陆成功，获取返回的数据，即html文件*/
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        String ee = httpClient.execute(httpost,responseHandler);
        System.out.println("eeeeeeeeeeeeee=========="+ee);
       // httpost.abort();
      //  DefaultHttpClient httpclient2 = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://zp.hnzpsc.com/company/41087.html");

       // HttpGet httpget = new HttpGet("https://www.zptong.com/jobs/jobs-show-98729-.htm");



        String responseBody = "";
        try {
             responseBody =  httpClient.execute(httpget,responseHandler);
        } catch (Exception e) {
            e.printStackTrace();
            responseBody = null;
        } finally {
            httpget.abort();
            httpClient.close();
        }
        System.out.println("ssssssssssssssss"+responseBody);
            return true;
    }

    /*main方法*/
    public static void main(String[] args) throws Exception {
        rencai renRen = new rencai();
        renRen.login();
    }
}
